<template>
  <el-dialog :visible.sync="value" :before-close="cancel">
    <template slot="title">
      上分手续费配置
    </template>
    <div style="height: 300px;overflow: scroll;">
      <el-form :model="form" :rules="refRule" ref="refForm" :label-width="formLabelWidth">
        <el-card
          style="margin-bottom: 10px;"
          shadow="never">
          <div slot="header">上分手续费配置</div>
          <el-form-item label="上分手续费比例(%)"  prop="feeRate">
            <el-col :span="8">
              <el-input @keyup.enter.native="doSave({action: 'saveForm', form: 'refForm'})" v-model.number="form.feeRate">
                <template slot="append">%</template>
              </el-input>
            </el-col>
            <el-col :span="24">
              <el-tip>单笔上分手续费比例，用作与佣金结算</el-tip>
            </el-col>
          </el-form-item>
          <el-form-item label="手续费上限"  prop="feeLimit">
            <el-col :span="8">
              <el-input @keyup.enter.native="doSave({action: 'saveForm', form: 'refForm'})" v-model.number="form.feeLimit">
                <template slot="append">元</template>
              </el-input>
            </el-col>
            <el-col :span="24">
              <el-tip>单笔上分手续费金额上限，用作与佣金结算，0为不限制</el-tip>
            </el-col>
          </el-form-item>
        </el-card>
        <el-card
          style="margin-bottom: 10px;"
          shadow="never">
          <div slot="header">上分返利百分比</div>
          <el-form-item label="上分返利比例((%)" prop="retRate">
            <el-col :span="8">
              <el-input @keyup.enter.native="doSave({action: 'saveForm', form: 'refForm'})" v-model.number="form.retRate">
                <template slot="append">%</template>
              </el-input>
            </el-col>
            <el-col :span="24">
              <el-tip>按照百分比比例返利上分手续费给代理商，建议填写100%（上分获得手续费全返代理商</el-tip>
            </el-col>
          </el-form-item>
          <el-form-item label="返利上限"  prop="retLimit">
            <el-col :span="8">
              <el-input @keyup.enter.native="doSave({action: 'saveForm', form: 'refForm'})" v-model.number="form.retLimit">
                <template slot="append">元</template>
              </el-input>
            </el-col>
            <el-col :span="24">
              <el-tip>上分手续费返利金额上限，0为不限制</el-tip>
            </el-col>
          </el-form-item>
        </el-card>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="doSave({action: 'saveForm', form: 'refForm'})">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>

  import {form, factory} from '@/build'
  import {getUpAmountsApportion, editUpAmountsApportion} from '@/services/api/commission';
  import ElTip from "@/components/Tip/index";

  export default {
    name: "platform-fee-apportion-dialog",
    components: {ElTip},
    props: ['value', 'id'],
    mixins: [form, factory],
    data() {
      return {
        formLabelWidth: '180px',
        keywords: '',
        form: {
        },
        refRule: {
          'feeRate': factory.getRule('percent'),
          'retRate': factory.getRule('percent'),
          'feeLimit': factory.getRule('money'),
          'retLimit': factory.getRule('money'),
        },
      }
    },
    mounted() {
      this.bindGet(getUpAmountsApportion, 'form', {
        sendingData: {id: this.id},
      })
      this.getAll()
      this.bindSave(editUpAmountsApportion, 'saveForm', 'form', {
        beforeSend: () =>{
          return Object.assign(this.form,{id:this.id})
        },
        afterSuccess: () => {
          this.cancel()
          this.$parent.getAll()
        }
      });
    },
    methods: {
      cancel() {
        this.$emit('input', false);
      },
    },

  }
</script>

<style lang="scss" scoped>
  .header {
    font-weight: bold;
  }

</style>
